/**
  ******************************************************************************
  * @file    User/LL/ts32fx_irq.c
  * @author  TOPSYS Application Team
  * @version V1.0.0
  * @date    02-11-2018
  * @brief   This file contains all the Interrupt IRQ firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2018 TOPSYS</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "ts32fx_system.h"
#include "ts32fx_irq.h"
#include "TM1668.h"
#include "TkLib.h"
#include "user.h"

/** @addtogroup Template_Project
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M0 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
    
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
    /* Go to infinite loop when Hard Fault exception occurs */
    while(1) {
        
    }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
    
}

/**
  * @brief  This function handles PendSV_Handler exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
    
}

/**
 * @brief  This function handles SysTick Handler.
 * @param  None
 * @retval None
 */
void SysTick_Handler(void)
{
    SysTickCnt++;
}

/******************************************************************************/
/*                 TS32Fx Peripherals Interrupt Handlers                      */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (ts32fx_startup.c).                                                  */
/******************************************************************************/

/** @defgroup LVD_Interrupt LVD Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  LVD Interrupt handler
  * @param  None.
  * @retval None.
  */
void LVD_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup TK_Interrupt TK Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  TK Interrupt handler
  * @param  None.
  * @retval None.
  */
void TK_IRQHandler(void)
{
    if(TK->INTPND & LL_TK_INTPND_KEYIRQ_PENDING) {
        TK->INTPND = LL_TK_INTPND_KEYIRQ_PENDING;
        /* TK->KEYPND = 0xFFFFFFFF; */
        TK->KEYPND = TK->KEYPND;
    }
}

/** 
  * @brief  TK_DONE Interrupt handler
  * @param  None.
  * @retval None.
  */
void TK_DONE_IRQHandler(void)
{
    if(TK->INTPND & LL_TK_INTPND_SCDN_PENDING) {
        TK->INTPND = LL_TK_INTPND_SCDN_PENDING;  
        #if USE_TK_JLINK_DEBUG
        //hal_tk_jlink_debug_print_sampval(8);
        hal_tk_jlink_debug_func();
        #endif
        
        /* TK->SCDOPND = 0xFFFFFFFF; */
        TK->SCDOPND = TK->SCDOPND;
    }
}

/** 
  * @brief  TK_OVF Interrupt handler
  * @param  None.
  * @retval None.
  */
void TK_OVF_IRQHandler(void)
{
   if(TK->INTPND & LL_TK_INTPND_SPOVF_PENDING) {
        TK->INTPND = LL_TK_INTPND_SPOVF_PENDING;
    }
}

/** 
  * @brief  TK_OVT Interrupt handler
  * @param  None.
  * @retval None.
  */
void TK_OVT_IRQHandler(void)
{
    if(TK->INTPND & LL_TK_INTPND_SCANOVT_PENDING) {
        TK->INTPND = LL_TK_INTPND_SCANOVT_PENDING;
        /* TK->SCOVPND = 0xFFFFFFFF; */
        TK->SCOVPND = TK->SCOVPND;
    }
}

/**
  * @}
  */


/** @defgroup UART_Interrupt UART Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  Uart0 Interrupt handler
  * @param  None.
  * @retval None.
  */
void UART0_IRQHandler(void)
{
    /* Get the value of the interrupt flag bit register */
    #if USE_TK_TOOL_DEBUG
	hal_tk_tool_debug_irq_handle();
	#endif
    
    #if USE_TK_SW_ALG_TOOL_DEBUG
    tk_sw_alg_tool_debug_irq_handle();
    #endif
}

/** 
  * @brief  Uart1 Interrupt handler
  * @param  None.
  * @retval None.
  */
void UART1_IRQHandler(void)
{
    /* Get the value of the interrupt flag bit register */
    #if USE_TK_SW_ALG_TOOL_DEBUG
    tk_sw_alg_tool_debug_irq_handle();
    #endif
}


/**
  * @}
  */


/** @defgroup SPI_Interrupt SPI Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  SPI0 Interrupt handler
  * @param  None.
  * @retval None.
  */
void SPI0_IRQHandler(void)
{

}

/** 
  * @brief  SPI1 Interrupt handler
  * @param  None.
  * @retval None.
  */
void SPI1_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup GPIO_Interrupt GPIO Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  GPIOA Interrupt handler
  * @param  None.
  * @retval None.
  */
void GPIOA_IRQHandler(void)
{

}

/** 
  * @brief  GPIOB Interrupt handler
  * @param  None.
  * @retval None.
  */
void GPIOB_IRQHandler(void)
{

}

/** 
  * @brief  GPIOC Interrupt handler
  * @param  None.
  * @retval None.
  */
void GPIOC_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup WKPND_Interrupt WKPND Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  WKPND Interrupt handler
  * @param  None.
  * @retval None.
  */
void WKPND_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup TIMER_Interrupt TIMER Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  TIMER0 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM0_IRQHandler(void)
{
counter ++;
}

/** 
  * @brief  TIMER1 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM1_IRQHandler(void)
{	
	  if(LL_TIMER_CNT_PENDING_GET(TIMER1))
    {
        LL_TIMER_CNT_PENDING_CLR(TIMER1);
			  timer_irq_count++;			
    }
    if(LL_TIMER_CAP_PENDING_GET(TIMER1))
    {
        TIMER1->TMR_CNT = 0x0000;
        LL_TIMER_CAP_PENDING_CLR(TIMER1);
    }
}

/** 
  * @brief  TIMER2 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM2_IRQHandler(void)
{

}

/** 
  * @brief  TIMER3 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM3_IRQHandler(void)
{

}

/** 
  * @brief  TIMER4 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM4_IRQHandler(void)
{

}

/** 
  * @brief  TIMER5 Interrupt handler
  * @param  None.
  * @retval None.
  */
void TIM5_IRQHandler(void)
{
 counter++;
}

/**
  * @}
  */


/** @defgroup ADKEY_Interrupt ADKEY Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  ADKEY Interrupt handler
  * @param  None.
  * @retval None.
  */
void ADKEY_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup CRC_DMA_Interrupt CRC_DMA Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  CRC_DMA Interrupt handler
  * @param  None.
  * @retval None.
  */
void CRC_DMA_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup COMP_Interrupt COMP Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  COMP Interrupt handler
  * @param  None.
  * @retval None.
  */
void COMP_IRQHandler(void)
{

}

/**
  * @}
  */


/** @defgroup WDT_Interrupt WDT Interrupt Handle function
  * @brief    Interrupt Handle function
  * @{
  */

/** 
  * @brief  WDT Interrupt handler
  * @param  None.
  * @retval None.
  */
void WDT_IRQHandler(void)
{
    LL_WDT_KEY_SET(WDT, LL_WDT_KEY_FEED_DOG);
}

/**
  * @}
  */


/**
  * @}
  */

/*************************** (C) COPYRIGHT 2018 TOPSYS ***** END OF FILE *****/

